﻿-- =========================================================================================================
-- Author:		MICHAEL RITACCO
-- Copyright:	2010 MEKHANO GROUP LLC
-- Version:		10/02/2010 1.0
-- =========================================================================================================
CREATE PROCEDURE [flcr].[api_device_config_sel_lov]
@DEVICE_CONFIG_ID INT = NULL
,@DEVICE_ID INT = NULL
,@DEVICE_CONFIG_PROPERTY_ID INT = NULL
,@PNAME_DEVICE_PROP_TYPE INT = NULL
,@PVALUE_DEVICE_PROP_TYPE INT = NULL 

AS
BEGIN TRY
  
	SELECT	A.[DEVICE_CONFIG_ID]
			,A.[DEVICE_ID]
			,A.[DEVICE_CONFIG_PROPERTY_ID]
			,B.[PNAME_DEVICE_PROP_TYPE]
			,B.[PVALUE_DEVICE_PROP_TYPE]
			,C.[DEVICE_PROP_TYPE_NAME] AS [PNAME_DEVICE_PROP_TYPE_NAME]
			,D.[DEVICE_PROP_TYPE_NAME] AS [PVALUE_DEVICE_PROP_TYPE_NAME]
	  FROM	[FLCR].[DEVICE_CONFIG] A
	 INNER JOIN [FLCR].[DEVICE_CONFIG_PROPERTY] B
		ON	A.[DEVICE_CONFIG_PROPERTY_ID] = B.[DEVICE_CONFIG_PROPERTY_ID]
	 INNER JOIN [FLCR].[DEVICE_PROPERTY_TYPE] C
		ON	B.[PNAME_DEVICE_PROP_TYPE]  = C.[DEVICE_PROP_TYPE]
	 INNER JOIN [FLCR].[DEVICE_PROPERTY_TYPE] D
		ON	B.[PVALUE_DEVICE_PROP_TYPE]  = D.[DEVICE_PROP_TYPE]
     WHERE	A.[DEVICE_CONFIG_ID] = COALESCE(@DEVICE_CONFIG_ID,A.[DEVICE_CONFIG_ID])
	   AND	A.[DEVICE_ID] = COALESCE(@DEVICE_ID,A.[DEVICE_ID])
	   AND	A.[DEVICE_CONFIG_PROPERTY_ID] = COALESCE(@DEVICE_CONFIG_PROPERTY_ID,A.[DEVICE_CONFIG_PROPERTY_ID])
	   AND	C.[DEVICE_PROP_TYPE] = COALESCE(@PNAME_DEVICE_PROP_TYPE,C.[DEVICE_PROP_TYPE])
	   AND	D.[DEVICE_PROP_TYPE] = COALESCE(@PVALUE_DEVICE_PROP_TYPE,D.[DEVICE_PROP_TYPE])

END TRY
BEGIN CATCH
	EXEC [flcr].[utl_getDBError];
END CATCH
